<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>FormLayout 表单布局</title>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

		<script src="__PUBLIC__/scripts/boot.js" type="text/javascript"></script>

		<style type="text/css">
			.td1 {
				text-align: right;
				
			}

		</style>

	</head>
	<body>
		<h1>项目投资及股权变动信息</h1>
		<div style="width:900px;">
			<div class="mini-toolbar" style="padding:2px;">
				<table style="width:100%;">
					<tr>
						<td style="width:100%;"><span>项目名称: {$_SESSION['pname']}</span> &nbsp <span>项目经理: {$_SESSION['managername']}</span></td>
						<td style="white-space:nowrap;"></td>
					</tr>
				</table>
			</div>
		</div>
		<br />
		<div style="width:900px;">
			<div class="mini-toolbar" style="border-bottom:0;padding:2px;">
				<table style="width:100%;">
					<tr>
						<td style="width:100%;"><a class="mini-button" iconCls="icon-add" onclick="add()">增加</a><a class="mini-button" onclick="ExportExcel()">导出Excel</a></td>
						<td style="white-space:nowrap;"></td>
					</tr>
				</table>
			</div>
		</div>
		<div id="datagrid1" class="mini-datagrid" style="width:900px;height:300px;"
		url="__APP__/Post/post_1"  idField="id" allowResize="true"
		sizeList="[10,20,30,50]" pageSize="10">
			<div property="columns">
				<div type="indexcolumn" headerAlign="center" >
					序号
				</div>
				<div field="investor" width="80" headerAlign="center" allowSort="true">
					投资基金主体
				</div>
				<div field="investnum" width="80" headerAlign="center" allowSort="true">
					投资方式
				</div>
				<div field="date" width="160" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd">
					日期
				</div>
				<div field="header" width="160" headerAlign="center" allowSort="true">
					领投机构
				</div>
				<div field="maininvestor" width="160" headerAlign="center" allowSort="true">
					主要投资机构
				</div>

			</div>
		</div>

		<div id="win1" class="mini-window" title="详细内容" style="width:800px;"
		showMaxButton="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
		>

			<fieldset style="width:700px;border:solid 1px #aaa;margin-top:8px;position:relative;">
				<legend>
					项目投资及股权变动信息
				</legend>
				<div id="editForm1">
					<input class="mini-hidden" name="icid"/>
					<table style="padding-left:200px;">
						<tr>
							<td class="td1"><label for="investor" >投资基金主体 </label></td>
							<td>
							<input name="investor" showNullItem="true" class="mini-combobox" url="__APP__/Filter/fund" value="" textField="text" valueField="text" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="investnum" >投资方式</label></td>
							<td>
							<input class="mini-combobox" id="investnum" name="investnum"  url="__PUBLIC__/data/times.txt"   value=""  textField="text" valueField="id" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="date" >投资/股权变动日期</label></td>
							<td>
							<input class="mini-datepicker" id="date" name="date" format="yyyy-MM-dd" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="reason" >变动原因说明</label></td>
							<td>
							<input class="mini-textbox" id="reason" type="text" name="reason"  />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="header" >领投机构 </label></td>
							<td>
							<input class="mini-textbox" id="header" name="header" type="text" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="maininvestor" >主要投资机构 </label></td>
							<td>
							<input class="mini-textbox" id="maininvestor" name="maininvestor" type="text" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="A" >项目本轮新增股数(万股)*</label></td>
							<td>
							<input class="mini-textbox"  id="A1" name="A" value="" onvaluechanged="calculate1()"/>
							</td>
						</tr>

						<tr>
							<td  class="td1"><label for="B" >项目增资后股数(万股)*</label></td>
							<td>
							<input class="mini-textbox"  id="B1"  name="B"  onvaluechanged="calculate1()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="C" >项目增资每股单价(元/股)*</label></td>
							<td>
							<input class="mini-textbox"  id="C1" type="text" name="C" value="" onvaluechanged="calculate1()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="E" >常春藤认购股数(万股)*</label></td>
							<td>
							<input class="mini-textbox" id="E1" type="text" name="E" value="" onvaluechanged="calculate1()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="J" >项目本年度预期利润(万元)*</label></td>
							<td>
							<input class="mini-textbox"  id="J1" type="text" name="J" value="" onvaluechanged="calculate1()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="D" >本轮增资总金额(万元)</label></td>
							<td>
							<input class="mini-textbox" id="D1" type="text" name="D" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="F" >常春藤出资金额(万元)</label></td>
							<td>
							<input class="mini-textbox" id="F1" type="text" name="F" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="G" >常春藤持股比例(%)</label></td>
							<td>
							<input class="mini-textbox" id="G1" type="text" name="G" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="H" >项目投资后估值(万元)</label></td>
							<td>
							<input class="mini-textbox" id="H1" type="text" name="H" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="I" >项目投资前估值(万元)</label></td>
							<td>
							<input class="mini-textbox" id="I1" type="text" name="I" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="K" >投资后估值/本年度预期利润(P/E)</label></td>
							<td>
							<input class="mini-textbox" id="K1" type="text" name="K" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="L" >投资前估值/本年度预期利润(P/E)</label></td>
							<td>
							<input class="mini-textbox" id="L1" type="text" name="L" value="" />
							</td>
						</tr>
						<tr>
							<td></td>
							<td>
							<a class="mini-button" iconCls="icon-save" plain="true" onclick="updateForm()">保存</a> 
							</td>
							
						</tr>
					</table>

				</div>
			</fieldset>
		</div>

		<div id="win2" class="mini-window" title="新增项目估值变动" style="width:800px;"
		showMaxButton="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
		>
			<fieldset style="width:700px;border:solid 1px #aaa;margin-top:8px;position:relative;">
				<legend>
					项目投资及股权变动信息
				</legend>
				<div id="addForm1">
					<table>
						<tr>
							<td class="td1"><label for="investor" >投资基金主体 </label></td>
							<td>
								<input name="investor" showNullItem="true" class="mini-combobox" url="__APP__/Filter/fund" value="" textField="text" valueField="text" />
								</td>
						</tr>

						<tr>
							<td class="td1"><label for="investnum" >投资方式</label></td>
							<td>
							<input class="mini-combobox" id="investnum" name="investnum"  url="__PUBLIC__/data/times.txt"   value=""  textField="text" valueField="id" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="date" >投资/股权变动日期</label></td>
							<td>
							<input class="mini-datepicker" id="date" name="date" format="yyyy-MM-dd" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="reason" >变动原因说明</label></td>
							<td>
							<input class="mini-textbox" id="reason" type="text" name="reason" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="header" >领投机构 </label></td>
							<td>
							<input class="mini-textbox" id="header" name="header" type="text" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="maininvestor" >主要投资机构 </label></td>
							<td>
							<input class="mini-textbox" id="maininvestor" name="maininvestor" type="text" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="A" >项目本轮新增股数(万股)*</label></td>
							<td>
							<input class="mini-textbox"  id="A" name="A" value="" onvaluechanged="calculate()"/>
							</td>
						</tr>

						<tr>
							<td  class="td1"><label for="B" >项目增资后股数(万股)*</label></td>
							<td>
							<input class="mini-textbox"  id="B"  name="B"  onvaluechanged="calculate()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="C" >项目增资每股单价(元/股)*</label></td>
							<td>
							<input class="mini-textbox"  id="C" type="text" name="C" value="" onvaluechanged="calculate()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="E" >常春藤认购股数(万股)*</label></td>
							<td>
							<input class="mini-textbox" id="E" type="text" name="E" value="" onvaluechanged="calculate()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="J" >项目本年度预期利润(万元)*</label></td>
							<td>
							<input class="mini-textbox"  id="J" type="text" name="J" value="" onvaluechanged="calculate()"/>
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="D" >本轮增资总金额(万元)</label></td>
							<td>
							<input class="mini-textbox" id="D" type="text" name="D" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="F" >常春藤出资金额(万元)</label></td>
							<td>
							<input class="mini-textbox" id="F" type="text" name="F" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="G" >常春藤持股比例(%)</label></td>
							<td>
							<input class="mini-textbox" id="G" type="text" name="G" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="H" >项目投资后估值(万元)</label></td>
							<td>
							<input class="mini-textbox" id="H" type="text" name="H" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="I" >项目投资前估值(万元)</label></td>
							<td>
							<input class="mini-textbox" id="I" type="text" name="I" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="K" >投资后估值/本年度预期利润(P/E)</label></td>
							<td>
							<input class="mini-textbox" id="K" type="text" name="K" value="" />
							</td>
						</tr>

						<tr>
							<td class="td1"><label for="L" >投资前估值/本年度预期利润(P/E)</label></td>
							<td>
							<input class="mini-textbox" id="L" type="text" name="L" value="" />
							</td>
						</tr>
						<tr>
							<td>					
							</td>
							<td >
							<a class="mini-button" iconCls="icon-add" plain="true" onclick="addForm()">发送</a> 
							</td>
						</tr>
					</table>

				</div>
			</fieldset>
		</div>
		<script type="text/javascript">
			mini.parse();

			var grid = mini.get("datagrid1");

			grid.load();

			var pid = "{$_SESSION['pid']}";
			if(pid.length < 1) {
				mini.alert("尚未选择项目！", "提示", function() {
					window.CloseOwnerWindow('refresh');
				});

			}

			var t = mini.get("date");
			t.setValue(new Date());

			grid.on("rowclick", function(e) {
				//alert(e.record.mid);//弹个ID出来就好了

				showWindow();
			});

			var db = new mini.DataBinding();
			db.bindForm("editForm1", grid);

			function showWindow() {
				var win = mini.get("win1");
				win.show();
			}

			//对"createtime"字段，进行降级排序
			grid.sortBy("icid", "desc");
			/////////////////////////////////

			function search() {
				var key1 = document.getElementById("key1").value;
				grid.load({
					key1 : key1
				});
			}


			$("#key1").bind("keydown", function(e) {
				if(e.keyCode == 13) {
					search();
				}
			});
			///////////////////////////////////////////////////////
			function add() {
				if(checkauth()) {
					var win = mini.get("win2");
					win.show();
				}
			}

			function ExportExcel() {
				 var columns = grid.getBottomColumns();
         columns = columns.clone();
        for (var i = columns.length - 1; i >= 0; i--) {
                    var column = columns[i];
                    if (!column.field) {
                        columns.removeAt(i);
                    } else {
                        var c = { header: column.header, field: column.field };
                        columns[i] = c;
                    }
         }
        
         var data = grid.getData();      //获取表单多个控件的数据
         var json = mini.encode(data);   //序列化成JSON
         var header = mini.encode(columns); 
            //mini.alert(data[0]['mid']);
         window.location.href="__APP__/File/excel?header="+header+"&data="+json;
			}

			function addForm() {
				//提交表单数据

				var form = new mini.Form("#addForm1");
				form.validate();
				if(form.isValid() == false)
					return;

				var data = form.getData(true);
				//获取表单多个控件的数据

				$.ajax({
					url : "__APP__/Post/post_1_add",
					type : "post",
					data : {
						Data : data
					},
					success : function(text) {
						alert("提交成功");
						grid.reload();
						var win = mini.get("win2");
						win.hide();
					}
				});

			}
			function updateForm() {
				//提交表单数据
			if(checkauth())
			{var form = new mini.Form("#editForm1");
				form.validate();
				if(form.isValid() == false)
					return;

				var data = form.getData(true);
				//获取表单多个控件的数据

				$.ajax({
					url : "__APP__/Post/post_1_update",
					type : "post",
					data : {
						Data : data
					},
					success : function(text) {
						alert("提交成功");
						grid.reload();
						var win = mini.get("win1");
						win.hide();
					}
				});
				}
				else{
					
					var win = mini.get("win1");
					win.hide();
				}
			}
			function resetForm() {
				var form = new mini.Form("#addForm1");
				form.reset();
			}

			function getForm() {
				//提交表单数据
				var form = new mini.Form("#addForm1");

				var data = form.getData();
				//获取表单多个控件的数据
				var json = mini.encode(data);
				//序列化成JSON
				mini.alert(json);
			}

			function CloseWindow(action) {

				if(window.CloseOwnerWindow)
					window.CloseOwnerWindow(action);
				
				else
					window.close();

			}

			function times() {
				var d = mini.get("investnum").getText();
				if(d === "第一次") {
					mini.get("reason").setValue("首次投资");
					mini.get("method").setValue("新增");
				} else if(d === "第二次") {
					mini.get("reason").setValue("再度融资");
					mini.get("method").setValue("新增");
				} else if(d === "第三次") {
					mini.get("reason").setValue("股改");
					mini.get("method").setValue("新增");
				}
			}

			function calculate1() {
				var a = mini.get("A1").value;
				var b = mini.get("B1").value;
				var c = mini.get("C1").value;
				var e = mini.get("E1").value;
				var j = mini.get("J1").value;

				if(a != "" && b != "" && c != "" && e != "" && j != "") {

					
					var d = a * c;
					mini.get("D1").setValue(d.toFixed(2));

					var f = c * e;
					mini.get("F1").setValue(f.toFixed(2));

					var g = e / b*100;
					mini.get("G1").setValue(g.toFixed(2));
					
					var h = b * c;
					mini.get("H1").setValue(h.toFixed(2));

					var i = h - d;
					mini.get("I1").setValue(i.toFixed(2));

					var k = h / j;
					mini.get("K1").setValue(k.toFixed(2));

					var l = i / j;
					mini.get("L1").setValue(l.toFixed(2));
				}
			}
			function calculate() {
				var a = mini.get("A").value;
				var b = mini.get("B").value;
				var c = mini.get("C").value;
				var e = mini.get("E").value;
				var j = mini.get("J").value;

				if(a != "" && b != "" && c != "" && e != "" && j != "") {

					
					var d = a * c;
					mini.get("D").setValue(d.toFixed(2));

					var f = c * e;
					mini.get("F").setValue(f.toFixed(2));

					var g = e / b*100;
					mini.get("G").setValue(g.toFixed(2));
					
					var h = b * c;
					mini.get("H").setValue(h.toFixed(2));

					var i = h - d;
					mini.get("I").setValue(i.toFixed(2));

					var k = h / j;
					mini.get("K").setValue(k.toFixed(2));

					var l = i / j;
					mini.get("L").setValue(l.toFixed(2));
				}
			}

			function checkauth() {
				var state = "{$_SESSION['state']}";
				if(state=="休眠"){
					mini.alert("项目休眠，需要在基本信息表中激活！");
					return false;
				}
				var uname = "{$_SESSION['nickname']}";
				var mname = "{$_SESSION['membername']}";
				var depart = "{$_SESSION['depart']}";
				var pos = mname.indexOf(uname);
				if(pos == -1 && depart != "营运" && uname != "{$_SESSION['managername']}") {
					mini.alert("无操作权限！");
					return false;
				} else
					return true;
			}
		</script>

	</body>
</html>